package day13;

import java.util.Arrays;

/**
 * <a href="https://leetcode.cn/problems/remove-duplicates-from-sorted-array/">23. 删除有序数组中的重复项</a>
 *
 * @author admin
 */
public class Answer {

    public static void main(String[] args) {
        Answer answer = new Answer();

        System.out.println(answer.removeDuplicates(new int[]{0,0,1,1,1,2,2,3,3,4}));
    }

    public int removeDuplicates(int[] nums) {
        if (nums.length == 0) return 0;
        if (nums.length == 1) return 1;
        int a = nums[0];
        int j = 1;
        for (int i = 0; i <= nums.length - 1; i++) {
            int b = nums[i];
            if (a != b) {
                a = b;
                ++j;
                nums[j - 1] = a;
            }
        }
        System.out.println(Arrays.toString(nums));
        return j;
    }
}
